package com.liucanwen.citylist.hccitylist.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.liucanwen.citylist.R;

import java.util.List;

/**
 * Created by Administrator on 2016/9/1.
 */
public class CityAdapter extends BaseAdapter {
    private Context mContext ;
    private List<String> mDatas ;

    public CityAdapter(Context context, List datas){
        mContext = context ;
        mDatas = datas ;
    }

    @Override
    public int getCount() {
        return mDatas==null?0:mDatas.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        if (mDatas==null)
            return convertView ;
        ViewHolder holder ;
        if ( convertView == null ){
            holder = new ViewHolder();
            convertView = View.inflate(mContext, R.layout.city_item,null);
            TextView cityName = (TextView) convertView.findViewById(R.id.cityName);
            holder.tv_char = (TextView) convertView.findViewById(R.id.tv_char);
//            TextView sectionTextView = (TextView) convertView.findViewById(R.id.sectionTextView);
            holder.cityName = cityName ;
            holder.view_line = convertView.findViewById(R.id.view_line);
//            holder.sectionTextView = sectionTextView ;
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        String city = mDatas.get(i);
        if ( city.length() == 1 ){
            holder.tv_char.setVisibility(View.VISIBLE);
            holder.cityName.setVisibility(View.GONE);
            holder.view_line.setVisibility(View.GONE);
            holder.tv_char.setText(mDatas.get(i));
        }else{
            holder.tv_char.setVisibility(View.GONE);
            holder.cityName.setVisibility(View.VISIBLE);
            holder.view_line.setVisibility(View.VISIBLE);
            holder.cityName.setText(mDatas.get(i));
        }

        return convertView;
    }

    private class ViewHolder{
        TextView cityName ;
        TextView tv_char ;
        View view_line;
    }


}
